package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ReservationDto;
import com.zzyl.entity.Reservation;
import com.zzyl.service.ReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "客户预约")
@RequestMapping("/customer/reservation")
@RequiredArgsConstructor
public class CustomerReservationController {
    private final ReservationService reservationService;
    @GetMapping("/cancelled-count")
    @ApiOperation("2.1 查询取消预约数量")
    public ResponseResult cancelledCount(){
        Integer count =reservationService.cancelReservationCount();
        return ResponseResult.success(count);
    }
    @GetMapping("/countByTime")
    @ApiOperation("2.2 查询每个时间段剩余预约次数")
    public ResponseResult countByTime(Long time){
        List<TimeCountVo> timeCountVo =reservationService.countReservationsForEachTimeWithinTimeRange(time);
        return ResponseResult.success(timeCountVo);
    }
    @PostMapping()
    @ApiOperation("2.3 新增预约")
    public ResponseResult addReservation(@RequestBody ReservationDto reservationDto){
        reservationService.insert(reservationDto);
        return ResponseResult.success();
    }
    @GetMapping("/page")
    @ApiOperation("2.4 分页查询预约信息")
    public ResponseResult<Reservation> page(@RequestParam(value = "status",required = false) Integer status, Integer pageNum, Integer pageSize){
        PageResponse<ReservationVo> Reservation=reservationService.findByPage(status,pageNum,pageSize);
        return ResponseResult.success(Reservation);

    }
    @PutMapping("/{id}/cancel")
    @ApiOperation("2.5 取消预约")
    public ResponseResult cancel(@PathVariable Long id){
        reservationService.cancelReservation(id);
        return ResponseResult.success();
    }





}
